<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<html>
<head>
  <%@ include file="/common/meta.jsp" %>
  <title>审批任务节点</title>
  <script type="text/javascript">
    $(function(){
      $("textarea").css({"min-width":"450px","min-height":"100px","max-width":"450px","max-height":"100px"});
      $("input[type=button]").css({"background":"#ffffff","display":"inline-block","cursor":"pointer"});//按钮的样式
      /*绑定同意方法下拉框*/
      $("#functionName").ligerComboBox({
        url: '${_ctx}/flow/function/getComboBoxData?processId=${processId}',
        valueField: 'id',
        textField: 'functionName',
        valueFieldID: 'functionId',
        selectBoxWidth: 173,
        width: 173,
        highLight:true,
        cancelable:true
      });
      /*绑定拒绝方法下拉框*/
      $("#disagreeFunctionName").ligerComboBox({
        url: '${_ctx}/flow/function/getComboBoxData?processId=${processId}',
        valueField: 'id',
        textField: 'functionName',
        valueFieldID: 'disagreeFunctionId',
        selectBoxWidth: 173,
        width: 173,
        highLight:true,
        cancelable:true
      });

      /*绑定查看页面下拉框*/
      $("#viewPageName").ligerComboBox({
        url:'${_ctx}/flow/workPage/getComboBoxData?processId=${processId}&typeName=1',
        valueField: 'id',
        textField: 'pageName',
        valueFieldID: 'viewPageId',
        selectBoxWidth: 173,
        width: 173,
        highLight:true,
        cancelable:true

      });
      /*岗位列表*/
      $("#mainGrid").ligerGrid({
        columns: [
          { display: 'id', name: 'id', hide: true, width: 60 },
          { display: '序号', width: 40, render: function (rowData, rowindex, value, column, rowid, page, pagesize) { return (page - 1) * pagesize + rowindex + 1; } },
          { display: '岗位名称', name: 'hostName', align: 'center', width: 160 },
          { display: '岗位代码', name: 'hostCode', align: 'center', width: 140 },
          { display: '组织机构', name: 'organization', align: 'center', width: 140 }
        ],
        width: '100%', heightDiff: -1,height:'50%',
        usePager:false,
        checkbox:true
      });
      /*接收通知岗位列表*/
      $("#mainGridNoticeHost").ligerGrid({
        columns: [
          { display: 'id', name: 'id', hide: true, width: 60 },
          { display: '序号', width: 40, render: function (rowData, rowindex, value, column, rowid, page, pagesize) { return (page - 1) * pagesize + rowindex + 1; } },
          { display: '岗位名称', name: 'hostName', align: 'center', width: 160 },
          { display: '岗位代码', name: 'hostCode', align: 'center', width: 140 },
          { display: '组织机构', name: 'organization', align: 'center', width: 140 }
        ],
        width: '100%', heightDiff: -1,height:'50%',
        usePager:false
      });

      /*角色列表*/
      $("#mainGridRole").ligerGrid({
        columns: [
          { display: 'id', name: 'id', hide: true, width: 60 },
          { display: '序号', width: 40, render: function (rowData, rowindex, value, column, rowid, page, pagesize) { return (page - 1) * pagesize + rowindex + 1; } },
          { display: '角色名称', name: 'roleName', align: 'center', width: 200 },
          { display: '角色代码', name: 'roleCode', align: 'center', width: 200 },
        ],
        width: '100%', heightDiff: -1,height:'50%',
        usePager:false,
        checkbox:true
      });
      /*接收通知角色列表*/
      $("#mainGridNoticeRole").ligerGrid({
        columns: [
          { display: 'id', name: 'id', hide: true, width: 60 },
          { display: '序号', width: 40, render: function (rowData, rowindex, value, column, rowid, page, pagesize) { return (page - 1) * pagesize + rowindex + 1; } },
          { display: '角色名称', name: 'roleName', align: 'center', width: 200 },
          { display: '角色代码', name: 'roleCode', align: 'center', width: 200 },
        ],
        width: '100%', heightDiff: -1,height:'50%',
        usePager:false
      });

      /*组织机构*/
      $("#mainGridOrganization").ligerGrid({
        columns: [
          { display: 'id', name: 'id', hide: true, width: 60 },
          { display: '序号', width: 40, render: function (rowData, rowindex, value, column, rowid, page, pagesize) { return (page - 1) * pagesize + rowindex + 1; } },
          { display: '机构名称', name: 'organizationName', align: 'center', width: 200 },
          { display: '机构代码', name: 'organizationCode', align: 'center', width: 200 },
        ],
        width: '100%', heightDiff: -1,height:'50%',
        usePager:false,
        checkbox:true
      });

      /*自定义执行人*/
      $("#mainGridUser").ligerGrid({
        columns: [
          { display: 'id', name: 'id', hide: true, width: 60 },
          { display: '序号', width: 40, render: function (rowData, rowindex, value, column, rowid, page, pagesize) { return (page - 1) * pagesize + rowindex + 1; } },
          { display: '帐号', name: 'account', align: 'center',width:100},
          { display: '名称', name: 'userName', align: 'center',width:100},
          { display: '类型', name: 'userType', align: 'center',width:60, render: function (row) {return 'employee' == row['userType'] ? '内部员工' : '合作伙伴'}},
        ],
        width: '100%', heightDiff: -1,height:'50%',
        usePager:false,
        checkbox:true
      });
      /*接收通知人列表*/
      $("#mainGridNoticeUser").ligerGrid({
        columns: [
          { display: 'id', name: 'id', hide: true, width: 60 },
          { display: '序号', width: 40, render: function (rowData, rowindex, value, column, rowid, page, pagesize) { return (page - 1) * pagesize + rowindex + 1; } },
          { display: '帐号', name: 'account', align: 'center',width:100},
          { display: '名称', name: 'userName', align: 'center',width:100},
          { display: '类型', name: 'userType', align: 'center',width:60, render: function (row) {return 'employee' == row['userType'] ? '内部员工' : '合作伙伴'}},
        ],
        width: '100%', heightDiff: -1,height:'50%',
        usePager:false
      });

      /*
       *接收并初始化节点
       */
      $("#currentNodeName").val(nodeObj['${currentNodeId}'].name);
      for(var node in nodeObj){
        var nodeChild = nodeObj[node];
        if(nodeChild.type != "start round" && node != '${currentNodeId}'){
          $("#disagreeAgreeNode").append("<option value='"+node+"'>"+nodeChild.name+"</option>");
          $("#agreeNode").append("<option value='"+node+"'>"+nodeChild.name+"</option>");
        }
      }
      $("#navtab1").ligerTab();

      /*任务执行人单选按钮的切换*/
      $("input[name=fkType]").click(function(){
        $(".post:eq("+$(this).index()+")").show().siblings().hide();
      });
      /*通知接收人单选按钮的切换*/
      $("input[name=notice]").click(function(){
        $(".notice:eq("+$(this).index()+")").show().siblings().hide();
      });
      loadExamine();
      loadNotice();
    });

    /*显示审批节点属性信息*/
    function loadExamine(){
      if(sessionStorage.getItem('examineJson') == "undefined"){
        return;
      }
      var properties = JSON.parse(sessionStorage.getItem('examineJson'));
      //同意方法
      var functionId = properties['functionId'];
      if(functionId){
        $.ajax({
          url:'${_ctx}/flow/function/getFunctionById',
          type:'post',
          dataType:'text',
          data:{functionId:functionId},
          success:function(functionName){
            $("#functionName").ligerComboBox().setText(functionName);
            $("#functionId").val(functionId);
          }
        });
      }
      //拒绝方法
      var disagreeFunctionId = properties["disagreeFunctionId"];
      if(disagreeFunctionId){
        $.ajax({
          url:'${_ctx}/flow/function/getFunctionById',
          type:'post',
          dataType:'text',
          data:{functionId:disagreeFunctionId},
          success:function(functionName){
            $("#disagreeFunctionName").ligerComboBox().setText(functionName);
            $("#disagreeFunctionId").val(disagreeFunctionId);
          }
        });
      }
      //同意节点
      var agreeNodeId = properties['agreeNodeId'];
      if(nodeObj[agreeNodeId]){
        var agreeNodeName = nodeObj[agreeNodeId].name;
        $("#agreeNode").val(agreeNodeId);
        var count=$("#node option").length;
        for(var i=0;i<count;i++)
        {
          if($("#agreeNode").get(0).options[i].text == agreeNodeName) {
            $("#agreeNode").get(0).options[i].selected = true;
            break;
          }
        }
      }

      //拒绝节点
      var disagreeAgreeNodeId = properties["disagreeNodeId"];
      if(nodeObj[disagreeAgreeNodeId]){
        var disagreeAgreeNodeName = nodeObj[disagreeAgreeNodeId].name;
        $("#disagreeAgreeNode").val(disagreeAgreeNodeId);
        var count1=$("#node option").length;
        for(var i=0;i<count1;i++)
        {
          if($("#disagreeAgreeNode").get(0).options[i].text == disagreeAgreeNodeName) {
            $("#disagreeAgreeNode").get(0).options[i].selected = true;
            break;
          }
        }
      }

      var viewPageId = properties['viewPageId'];
      if(viewPageId){
        $.ajax({
          url:'${_ctx}/flow/workPage/getPageNameById',
          type:'post',
          dataType:'json',
          data:{viewPageId:viewPageId},
          success:function(page){
            $("#viewPageName").ligerComboBox().setText(page.viewPageName);
            $("#viewPageId").val(viewPageId);
          }
        });
      }

      var allowStop = properties['allowStop'];
      var allowRecall = properties['allowRecall'];
      var allowHang = properties['allowHang'];
      if(allowStop == 1){
        $("#allowStop").attr("checked",true);
      }
      if(allowRecall == 1){
        $("#allowRecall").attr("checked",true);
      }
      if(allowHang == 1){
        $("#allowHang").attr("checked",true);
      }
      var radioId = properties['radioId'];
      var fkId = properties['fkId'];
      if(fkId == ""){
        return;
      }
      var fkIds = fkId.split(",");
      $("#"+radioId).click();
      if(radioId == "post"){//岗位
        $("#post").attr("checked",true);
        for(var i=0;i<fkIds.length;i++){
          $.ajax({
            url:"${_ctx}/bap/position/getPositionByCode",
            type:"post",
            dataType:"json",
            data:{code:fkIds[i]},
            success:function(model){
              var manager = $("#mainGrid").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              manager.addRow({
                id:model.code,
                hostName:model.name,
                hostCode:model.code,
                organization:model.organization.name
              }, firstRow, true);
            }
          });
        }
      }else if(radioId == "role"){//角色
        $("#role").attr("checked",true);
        for(var i=0;i<fkIds.length;i++){
          $.ajax({
            url:"${_ctx}/bap/featureRole/getFeturePoleByCode",
            type:"post",
            dataType:"json",
            data:{code:fkIds[i]},
            success:function(model){
              var manager = $("#mainGridRole").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              manager.addRow({
                id:model.code,
                roleName:model.name,
                roleCode:model.code
              }, firstRow, true);
            }
          });
        }
      } else if(radioId == "organizational"){//组织机构
        $("#organizational").attr("checked",true);
        for(var i=0;i<fkIds.length;i++){
          $.ajax({
            url:"${_ctx}/bap/organization/getOrganizationByCode",
            type:"post",
            dataType:"json",
            data:{code:fkIds[i]},
            success:function(model){
              var manager = $("#mainGridOrganization").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              manager.addRow({
                id:model.code,
                organizationName:model.name,
                organizationCode:model.code
              }, firstRow, true);
            }
          });
        }
      } else if(radioId == "executive"){//自定义接收人
        $("#executive").attr("checked",true);
        for(var i=0;i<fkIds.length;i++){
          $.ajax({
            url:"${_ctx}/bap/user/getUserAccount",
            type:"post",
            dataType:"json",
            data:{account:fkIds[i]},
            success:function(model){
              var manager = $("#mainGridUser").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              manager.addRow({
                id:model.account,
                account:model.account,
                userName:model.userName,
                userType:model.userType
              }, firstRow, true);
            }
          });
        }
      }else if(radioId == "promoter"){//流程发起人
        $("#promoter").attr("checked",true);
      }
    }
    /*加载通知*/
    function loadNotice(){
      if(sessionStorage.getItem('examineJson') == "undefined"){
        return;
      }
      var properties = JSON.parse(sessionStorage.getItem('examineJson'));
      var notices = properties["notices"];
      if(notices){
        var radioId = notices[0].radioId;
        var title = notices[0].title;
        var content = notices[0].content;
        var fkId = notices[0].fkId;
        var fkIds = fkId.split(",");
        $("#"+radioId).click();
        if(radioId =="noticeHost"){
          $("#noticeHostTitle").val(title);
          $("#noticeHostContent").val(content);
          for(var i=0;i<fkIds.length;i++){
            $.ajax({
              url:"${_ctx}/bap/position/getPositionByCode",
              type:"post",
              dataType:"json",
              data:{code:fkIds[i]},
              success:function(model){
                var manager = $("#mainGridNoticeHost").ligerGetGridManager();
                var firstRow = manager.getRow(0);
                manager.addRow({
                  id:model.code,
                  hostName:model.name,
                  hostCode:model.code,
                  organization:model.organization.name
                }, firstRow, true);
              }
            });
          }
        }else if(radioId =="noticeRole"){
          $("#noticeRoleTitle").val(title);
          $("#noticeRoleContent").val(content);
          for(var i=0;i<fkIds.length;i++){
            $.ajax({
              url:"${_ctx}/bap/featureRole/getFeturePoleByCode",
              type:"post",
              dataType:"json",
              data:{code:fkIds[i]},
              success:function(model){
                var manager = $("#mainGridNoticeRole").ligerGetGridManager();
                var firstRow = manager.getRow(0);
                manager.addRow({
                  id:model.code,
                  roleName:model.name,
                  roleCode:model.code
                }, firstRow, true);
              }
            });
          }
        }else if(radioId =="noticeExecutive"){
          $("#noticeUserTitle").val(title);
          $("#noticeUserContent").val(content);
          for(var i=0;i<fkIds.length;i++){
            $.ajax({
              url:"${_ctx}/bap/user/getUserAccount",
              type:"post",
              dataType:"json",
              data:{account:fkIds[i]},
              success:function(model){
                var manager = $("#mainGridNoticeUser").ligerGetGridManager();
                var firstRow = manager.getRow(0);
                manager.addRow({
                  id:model.account,
                  account:model.account,
                  userName:model.userName,
                  userType:model.userType
                }, firstRow, true);
              }
            });
          }
        }else if(radioId =="noticePromoter"){
          $("#noticeTitle").val(title);
          $("#noticeContent").val(content);
        }
      }
    }

    var nodeStr = sessionStorage.getItem("nodeStr");
    var nodeObj = JSON.parse(nodeStr);

    /*创建通知 json对像*/
    var isNoticesNull
    function noticesJson(){
      isNoticesNull = true;
      var str = "";
      var fkType = "";
      var radioId = "";
      var radios = $("input[name=notice]");
      for(var i=0;i<radios.length;i++){
        if(radios[i].checked){
          fkType = radios[i].value;
          radioId = radios[i].id;
        }
      }
      var noticeJson =[];
      //岗位
      if($("#noticeHost").get(0).checked){
        var manager = $("#mainGridNoticeHost").ligerGetGridManager();
        var rows = manager.getData();
        var hosts = [];
        $(rows).each(function () {
          hosts.push(this.hostCode);
        });
        str = hosts.join(",");
        if((str == "" && $("#noticeHostTitle").val()=="" && $("#noticeHostContent").val() == "") || (str != "" && $("#noticeHostTitle").val()!="" && $("#noticeHostContent").val() != "") ){
          noticeJson = [{radioId:radioId,fkId:str,fkType:fkType,noticeWay:$("#noticeHostWay").val(),
            title:$("#noticeHostTitle").val(),content:$("#noticeHostContent").val()}];
        }else if($("#noticeHostTitle").val()==""){
          isNoticesNull = false;
          $.ligerDialog.warn("通知标题不能为空")
        }else if($("#noticeHostContent").val()==""){
          isNoticesNull = false;
          $.ligerDialog.warn("通知内容不能为空")
        }else if(str==""){
          isNoticesNull = false;
          $.ligerDialog.warn("请选择通知接收人")
        }
      }else if($("#noticeRole").get(0).checked){//角色
        var manager = $("#mainGridNoticeRole").ligerGetGridManager();
        var rows = manager.getData();
        var roles = [];
        $(rows).each(function () {
          roles.push(this.roleCode);
        });
        str = roles.join(",");
        if((str == "" && $("#noticeRoleTitle").val()=="" && $("#noticeRoleContent").val() == "") || (str != "" && $("#noticeRoleTitle").val()!="" && $("#noticeRoleContent").val() != "")){
          noticeJson = [{radioId:radioId,fkId:str,fkType:fkType,noticeWay:$("#noticeRoleWay").val(),
            title:$("#noticeRoleTitle").val(),content:$("#noticeRoleContent").val()}];
        }else if($("#noticeRoleTitle").val()==""){
          isNoticesNull = false;
          $.ligerDialog.warn("通知标题不能为空")
        }else if($("#noticeRoleContent").val()==""){
          isNoticesNull = false;
          $.ligerDialog.warn("通知内容不能为空")
        }else if(str==""){
          isNoticesNull = false;
          $.ligerDialog.warn("请选择通知接收人")
        }
      }else if($("#noticeExecutive").get(0).checked){//自定义执行人
        var manager = $("#mainGridNoticeUser").ligerGetGridManager();
        var rows = manager.getData();
        var roles = [];
        $(rows).each(function () {
          roles.push(this.account);
        });
        str = roles.join(",");
        if((str == "" && $("#noticeUserTitle").val()=="" && $("#noticeUserContent").val() == "") || (str != "" && $("#noticeUserTitle").val()!="" && $("#noticeUserContent").val() != "")){
          noticeJson = [{radioId:radioId,fkId:str,fkType:fkType,noticeWay:$("#noticeUserWay").val(),
            title:$("#noticeUserTitle").val(),content:$("#noticeUserContent").val()}];
        }else if($("#noticeUserTitle").val()==""){
          isNoticesNull = false;
          $.ligerDialog.warn("通知标题不能为空")
        }else if($("#noticeUserContent").val()==""){
          isNoticesNull = false;
          $.ligerDialog.warn("通知内容不能为空")
        }else if(str==""){
          isNoticesNull = false;
          $.ligerDialog.warn("请选择通知接收人")
        }
      }else if($("#noticePromoter").get(0).checked){//流程发起人
        if(($("#noticeTitle").val()=="" && $("#noticeContent").val() == "") || ($("#noticeTitle").val()!="" && $("#noticeContent").val() != "")){
          noticeJson = [{radioId:radioId,fkId:'${currentUser}',fkType:fkType,noticeWay:$("#noticeWay").val(),
            title:$("#noticeTitle").val(),content:$("#noticeContent").val()}];
        }else if($("#noticeTitle").val()==""){
          isNoticesNull = false;
          $.ligerDialog.warn("通知标题不能为空")
        }else if($("#noticeContent").val()==""){
          isNoticesNull = false;
          $.ligerDialog.warn("通知内容不能为空")
        }
      }
      /*判断： 把没有值的属性删除*/
      for(var k in noticeJson[0]){
        if(noticeJson[0][k]==undefined || noticeJson[0][k] == "" || noticeJson[0][k] == null){
          noticeJson = "";
          break;
        }
      }
      return noticeJson;
    }

    /*创建单个节点的json对象*/
    function createJson(){
      var fkType="";
      var radioId="";
      var allowStop = 0;
      var allowRecall = 0;
      var allowHang = 0;
      var radios = $("input[name=fkType]");
      for(var i=0;i<radios.length;i++){
        if(radios[i].checked){
          fkType = radios[i].value;
          radioId = radios[i].id;
        }
      }
      if($("#allowStop").get(0).checked){
        allowStop = 1;
      }
      if($("#allowRecall").get(0).checked){
        allowRecall = 1;
      }
      if($("#allowHang").get(0).checked){
        allowHang = 1;
      }

      //定义json对象的模型，并赋值
      var ret = {radioId:radioId,type:nodeObj['${currentNodeId}'].type,fkId:fkId(),fkType:fkType, allowStop:allowStop, allowRecall:allowRecall,
        allowHang:allowHang, functionId:$("#functionId").val(),disagreeFunctionId:$("#disagreeFunctionId").val(),agreeNodeId:$("#agreeNode").val(),
        disagreeNodeId:$("#disagreeAgreeNode").val(),viewPageId:$("#viewPageId").val(),notices:noticesJson()};
      /*判断： 把没有值的属性删除*/
      for(var k in ret){
        if(ret[k]==undefined || ret[k] == "" || ret[k] == null || JSON.stringify(ret[k]) =="{}"){
          delete ret[k];
        }
      }
      return ret;
    }

    /*流程的执行人code*/
    function fkId(){
      var str = "";
      if($("#post").get(0).checked){
        var manager = $("#mainGrid").ligerGetGridManager();
        var rows = manager.getData();
        var hosts = [];
        $(rows).each(function () {
          hosts.push(this.id);
        });
        str = hosts.join(",");
      }else if($("#role").get(0).checked){//角色
        var manager = $("#mainGridRole").ligerGetGridManager();
        var rows = manager.getData();
        var roles = [];
        $(rows).each(function () {
          roles.push(this.id);
        });
        str = roles.join(",");
      }else if($("#organizational").get(0).checked){//组织机构
        var manager = $("#mainGridOrganization").ligerGetGridManager();
        var rows = manager.getData();
        var roles = [];
        $(rows).each(function () {
          roles.push(this.id);
        });
        str = roles.join(",");
      }else if($("#executive").get(0).checked){//自定义执行人
        var manager = $("#mainGridUser").ligerGetGridManager();
        var rows = manager.getData();
        var roles = [];
        $(rows).each(function () {
          roles.push(this.id);
        });
        str = roles.join(",");
      }else if($("#promoter").get(0).checked){//流程发起人
        str = '${currentUser}';
      }
      return str;
    }


    function f_addHost() {
      $.ligerDialog.open({title: "选择岗位", width: 450,height:450, allowClose: false, url: '${_ctx}/views/flow/positionList.jsp',
        buttons: [
          { text: '确定', onclick: function (item, dialog) {
            var hosts = dialog.frame.f_hostJson();
            for(var i=0;i<hosts.length;i++){
              var manager = $("#mainGrid").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              var data = manager.getData();
              var isOk = true;
              $(data).each(function () {
                if(this.id == hosts[i].id){
                  isOk = false;
                }
              });
              if(isOk){
                manager.addRow({
                  id:hosts[i].code,
                  hostName:hosts[i].name,
                  hostCode:hosts[i].code,
                  organization:hosts[i].organization
                }, firstRow, true);
              }
            }

            dialog.close();
          }
          },
          { text: '关闭', onclick: function (item, dialog) {
            dialog.close();
          }
          }
        ]
      });
    }

    /*删除岗位*/
    function f_deleteHost(){
      var manager = $("#mainGrid").ligerGetGridManager();
      manager.deleteSelectedRow();
    }

    /*角色*/
    function f_addRloe() {
      $.ligerDialog.open({title: "选择角色", width: 450,height:450, allowClose: false, url: '${_ctx}/views/flow/featureList.jsp',
        buttons: [
          { text: '确定', onclick: function (item, dialog) {
            var roles = dialog.frame.f_roleJson();
            for(var i=0;i<roles.length;i++){
              var manager = $("#mainGridRole").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              var data = manager.getData();
              var isOk = true;
              $(data).each(function () {
                if(this.id == roles[i].id){
                  isOk = false;
                }
              });
              if(isOk){
                manager.addRow({
                  id:roles[i].code,
                  roleName:roles[i].name,
                  roleCode:roles[i].code
                }, firstRow, true);
              }
            }

            dialog.close();
          }
          },
          { text: '关闭', onclick: function (item, dialog) {
            dialog.close();
          }
          }
        ]
      });
    }
    /*删除角色*/
    function f_deleteRole(){
      var manager = $("#mainGridRole").ligerGetGridManager();
      manager.deleteSelectedRow();
    }

    /**
     *组织机构
     */
    function f_addOrganization() {
      $.ligerDialog.open({title: "选择组织机构", width: 450,height:450, allowClose: false, url: '${_ctx}/views/flow/flow_OrganizationList.jsp',
        buttons: [
          { text: '确定', onclick: function (item, dialog) {
            var organizations = dialog.frame.f_organizationJson();
            for(var i=0;i<organizations.length;i++){
              var manager = $("#mainGridOrganization").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              var data = manager.getData();
              var isOk = true;
              $(data).each(function () {
                if(this.id == organizations[i].id){
                  isOk = false;
                }
              });
              if(isOk){
                manager.addRow({
                  id:organizations[i].code,
                  organizationName:organizations[i].name,
                  organizationCode:organizations[i].code
                }, firstRow, true);
              }
            }
            dialog.close();
          }
          },
          { text: '关闭', onclick: function (item, dialog) {
            dialog.close();
          }
          }
        ]
      });
    }
    /*删除机构*/
    function f_deleteOrganization(){
      var manager = $("#mainGridOrganization").ligerGetGridManager();
      manager.deleteSelectedRow();
    }

    /**
     *自定义执行人
     */
    function f_addUser() {
      $.ligerDialog.open( {width: 450,height:450, allowClose: false, url: '${_ctx}/views/flow/flow_userList.jsp',
        buttons: [
          { text: '确定', onclick: function (item, dialog) {
            var users = dialog.frame.f_userJson();
            for(var i=0;i<users.length;i++){
              var manager = $("#mainGridUser").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              var data = manager.getData();
              var isOk = true;
              $(data).each(function () {
                if(this.id == users[i].id){
                  isOk = false;
                }
              });
              if(isOk){
                manager.addRow({
                  id:users[i].account,
                  account:users[i].account,
                  userName:users[i].userName,
                  userType:users[i].userType
                }, firstRow, true);
              }
            }
            dialog.close();
          }
          },
          { text: '关闭', onclick: function (item, dialog) {
            dialog.close();
          }
          }
        ]
      });
    }
    /*删除自定义执行人*/
    function f_deleteUser(){
      var manager = $("#mainGridUser").ligerGetGridManager();
      manager.deleteSelectedRow();
    }

    /*添加通知接收岗位*/
    function f_addNoticeHost() {
      $.ligerDialog.open({title: "选择岗位", width: 450,height:450, allowClose: false, url: '${_ctx}/views/flow/positionList.jsp',
        buttons: [
          { text: '确定', onclick: function (item, dialog) {
            var hosts = dialog.frame.f_hostJson();
            for(var i=0;i<hosts.length;i++){
              var manager = $("#mainGridNoticeHost").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              var data = manager.getData();
              var isOk = true;
              $(data).each(function () {
                if(this.hostCode == hosts[i].code){
                  isOk = false;
                }
              });
              if(isOk){
                manager.addRow({
                  id:hosts[i].code,
                  hostName:hosts[i].name,
                  hostCode:hosts[i].code,
                  organization:hosts[i].organization
                }, firstRow, true);
              }
            }

            dialog.close();
          }
          },
          { text: '关闭', onclick: function (item, dialog) {
            dialog.close();
          }
          }
        ]
      });
    }

    /*删除通知接收岗位*/
    function f_deleteNoticeHost(){
      var manager = $("#mainGridNoticeHost").ligerGetGridManager();
      manager.deleteSelectedRow();
    }

    /**
     *添加通知接收角色
     */
    function f_addNoticeRloe() {
      $.ligerDialog.open({title: "选择角色", width: 450,height:450, allowClose: false, url: '${_ctx}/views/flow/featureList.jsp',
        buttons: [
          { text: '确定', onclick: function (item, dialog) {
            var roles = dialog.frame.f_roleJson();
            for(var i=0;i<roles.length;i++){
              var manager = $("#mainGridNoticeRole").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              var data = manager.getData();
              var isOk = true;
              $(data).each(function () {
                if(this.roleCode == roles[i].code){
                  isOk = false;
                }
              });
              if(isOk){
                manager.addRow({
                  id:roles[i].code,
                  roleName:roles[i].name,
                  roleCode:roles[i].code
                }, firstRow, true);
              }
            }

            dialog.close();
          }
          },
          { text: '关闭', onclick: function (item, dialog) {
            dialog.close();
          }
          }
        ]
      });
    }
    /*删除通知接收角色*/
    function f_deleteNoticeRole(){
      var manager = $("#mainGridNoticeRole").ligerGetGridManager();
      manager.deleteSelectedRow();
    }

    /**
     *添加通知接收人
     */
    function f_addNoticeUser() {
      $.ligerDialog.open( {width: 450,height:450, allowClose: false, url: '${_ctx}/views/flow/flow_userList.jsp',
        buttons: [
          { text: '确定', onclick: function (item, dialog) {
            var users = dialog.frame.f_userJson();
            for(var i=0;i<users.length;i++){
              var manager = $("#mainGridNoticeUser").ligerGetGridManager();
              var firstRow = manager.getRow(0);
              var data = manager.getData();
              var isOk = true;
              $(data).each(function () {
                if(this.id == users[i].id){
                  isOk = false;
                }
              });
              if(isOk){
                manager.addRow({
                  id:users[i].account,
                  account:users[i].account,
                  userName:users[i].userName,
                  userType:users[i].userType
                }, firstRow, true);
              }
            }
            dialog.close();
          }
          },
          { text: '关闭', onclick: function (item, dialog) {
            dialog.close();
          }
          }
        ]
      });
    }
    /*删除通知接收人*/
    function f_deleteNoticeUser(){
      var manager = $("#mainGridNoticeUser").ligerGetGridManager();
      manager.deleteSelectedRow();
    }

    /*获取下个节点的id*/
    function nextNodeId(){
      var agreeNodeId = $("#agreeNode").val();
      var disagreeAgreeId = $("#disagreeAgreeNode").val();
      var nextNodes = [];
      nextNodes.push(agreeNodeId);
      nextNodes.push(disagreeAgreeId);
      return nextNodes;
    }
  </script>
</head>
<body>
<table style="border-collapse:separate; border-spacing:10px;margin:10px auto;">
  <tr>
    <td style="text-align: right">当前节点：</td>
    <td>
      <input type="hidden" id="currentNodeId" name="currentNodeId" style="width: 170px;" value="${currentNodeId}" />
      <input type="text" id="currentNodeName" name="currentNodeName" style="width: 170px;background:#fff;" disabled="disabled" class="liger-textbox" />
    </td>
  </tr>
  <tr>
    <td style="text-align: right">同意执行方法：</td>
    <td>
      <input type="hidden" id="functionId" name="functionId" />
      <input type="text" id="functionName" name="functionName" />
    </td>
  </tr>
  <tr>
    <td style="text-align: right">拒绝执行方法：</td>
    <td>
      <input type="hidden" id="disagreeFunctionId" name="functionId" />
      <input type="text" id="disagreeFunctionName" name="functionName" />
    </td>
  </tr>
  <tr>
    <td style="text-align: right">同意执行节点：</td>
    <td>
      <select class="liger-textbox" id="agreeNode" style="width:175px;">
        <option value="" style="width:170px;"></option>
      </select>
    </td>
  </tr>
  <tr>
    <td style="text-align: right">拒绝执行节点：</td>
    <td>
      <select id="disagreeAgreeNode" class="liger-textbox" style="width:175px;">
        <option value="" ></option>
      </select>
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <input type="checkbox" checked="checked"  id="allowStop" />允许流程发起人终止&nbsp;
      <input type="checkbox" checked="checked"  id="allowRecall" />能否被上部撤回&nbsp;
      <input type="checkbox" checked="checked" id="allowHang" />允许挂起流程
    </td>
  </tr>
  <tr>
    <td style="text-align: right">查看页面：</td>
    <td>
      <input type="hidden" id="viewPageId" name="viewPageId" />
      <input type="text" id="viewPageName" name="viewPageName" />
    </td>
  </tr>
</table>
<div id="navtab1" style="width: 99%; overflow: hidden;margin:0 auto; border: 1px solid #D3D3d3;" class="liger-tab">

  <div tabid="home" title="任务执行人" lselected="true" style="padding:10px;">
    <input type="radio" id="post" name="fkType" value="group" checked="checked" />岗位&nbsp;&nbsp;
    <input type="radio" id="role" name="fkType" value="group" />角色&nbsp;&nbsp;
    <input type="radio" id="organizational" name="fkType" value="group" />组织机构&nbsp;&nbsp;
    <input type="radio" id="executive" name="fkType" value="user" />自定义执行人&nbsp;&nbsp;
    <input type="radio" id="promoter" name="fkType" value="user" />流程发起人
    <div>
      <%--岗位--%>
      <div class="post" style="margin-top:10px;" >
        <div>
          <input type="button" value="添加" id="addHost" onclick="f_addHost()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />&nbsp;&nbsp;
          <input type="button" value="删除" id="deleteHost" onclick="f_deleteHost()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />
        </div>
        <div id="mainGrid"style="margin-top:10px;">

        </div>
      </div>
      <%--角色--%>
      <div class="post" style="margin-top:10px;display:none;">
        <div>
          <input type="button" value="添加" id="addRole" onclick="f_addRloe()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />&nbsp;&nbsp;
          <input type="button" value="删除" id="deleteRole" onclick="f_deleteRole()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />
        </div>
        <div id="mainGridRole"style="margin-top:10px;">

        </div>
      </div>
      <%--组织机构--%>
      <div class="post" style="margin-top:10px;display:none;">
        <div>
          <input type="button" value="添加" id="addOrganization" onclick="f_addOrganization()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />&nbsp;&nbsp;
          <input type="button" value="删除" id="deleteOrganization" onclick="f_deleteOrganization()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />
        </div>
        <div id="mainGridOrganization"style="margin-top:10px;">

        </div>
      </div>
      <%--自定义执行人--%>
      <div class="post" style="margin-top:10px;display:none;">
        <div>
          <input type="button" value="添加" id="addUser" onclick="f_addUser()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />&nbsp;&nbsp;
          <input type="button" value="删除" id="deleteUser" onclick="f_deleteUser()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />
        </div>
        <div id="mainGridUser"style="margin-top:10px;">

        </div>
      </div>
      <%--流程发起人--%>
      <div class="post" style="margin-top:10px;display:none;text-align: center;">
        备注：由流程发起人执行任务
      </div>
    </div>
  </div>

  <div title="通知" showclose="true"style="padding:10px;">
    <input type="radio" id="noticeHost" name="notice" value="position" checked="checked" />通知岗位&nbsp;&nbsp;
    <input type="radio" id="noticeRole" name="notice" value="role" />通知角色&nbsp;&nbsp;
    <input type="radio" id="noticeExecutive" name="notice" value="user" />通知执行人&nbsp;&nbsp;
    <input type="radio" id="noticePromoter" name="notice" value="user" />通知发起人
    <div>
      <%--通知岗位--%>
      <div class="notice" style="margin-top:10px;" >
        <table style="border-collapse:separate; border-spacing:10px;">
          <tr>
            <td>通知类型：</td>
            <td>
              <input type="text" id="noticeHostWay" class="liger-textbox" name="noticeWay" style="width: 170px;background:#ffffff;" value="Email" disabled="disabled" />
            </td>
          </tr>
          <tr>
            <td>通知标题：</td>
            <td>
              <input type="text" id="noticeHostTitle" class="liger-textbox" name="noticeTitle" style="width: 170px;" />
            </td>
          </tr>
          <tr>
            <td valign="top">通知内容：</td>
            <td>
              <textarea id="noticeHostContent" name="noticeContent" ></textarea>
            </td>
          </tr>
        </table>
        <div>
          <input type="button" value="添加" id="addNoticeHost" onclick="f_addNoticeHost()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />&nbsp;&nbsp;
          <input type="button" value="删除" id="deleteNoticeHost" onclick="f_deleteNoticeHost()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />
        </div>
        <div id="mainGridNoticeHost"style="">

        </div>

      </div>
      <%--通知角色--%>
      <div class="notice" style="margin-top:10px;display:none;">
        <table style="border-collapse:separate; border-spacing:10px;">
          <tr>
            <td>通知类型：</td>
            <td>
              <input type="text" id="noticeRoleWay" class="liger-textbox" name="noticeWay" style="width: 170px;background:#ffffff;" value="Email" disabled="disabled" />
            </td>
          </tr>
          <tr>
            <td>通知标题：</td>
            <td>
              <input type="text" id="noticeRoleTitle" class="liger-textbox" name="noticeTitle" style="width: 170px;" />
            </td>
          </tr>
          <tr>
            <td valign="top">通知内容：</td>
            <td>
              <textarea id="noticeRoleContent" name="noticeContent" ></textarea>
            </td>
          </tr>
        </table>
        <div>
          <input type="button" value="添加" id="addNoticeRole" onclick="f_addNoticeRloe()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />&nbsp;&nbsp;
          <input type="button" value="删除" id="deleteNoticeRole" onclick="f_deleteNoticeRole()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />
        </div>
        <div id="mainGridNoticeRole"style="margin-top:10px;">

        </div>
      </div>
      <%--通知执行人--%>
      <div class="notice" style="margin-top:10px;display:none;">
        <table style="border-collapse:separate; border-spacing:10px;">
          <tr>
            <td>通知类型：</td>
            <td>
              <input type="text" id="noticeUserWay" class="liger-textbox" name="noticeWay" style="width: 170px;background:#ffffff;" value="Email" disabled="disabled" />
            </td>
          </tr>
          <tr>
            <td>通知标题：</td>
            <td>
              <input type="text" id="noticeUserTitle" class="liger-textbox" name="noticeTitle" style="width: 170px;" />
            </td>
          </tr>
          <tr>
            <td valign="top">通知内容：</td>
            <td>
              <textarea id="noticeUserContent" name="noticeContent" ></textarea>
            </td>
          </tr>
        </table>
        <div>
          <input type="button" value="添加" id="addNoticeUser" onclick="f_addNoticeUser()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />&nbsp;&nbsp;
          <input type="button" value="删除" id="deleteNoticeUser" onclick="f_deleteNoticeUser()" style="padding:2px 10px;border:1px solid #CCCCCC;border-radius:3px;" />
        </div>
        <div id="mainGridNoticeUser"style="margin-top:10px;">

        </div>
      </div>
      <%--通知发起人--%>
      <div class="notice" style="margin-top:10px;display:none;text-align: center;">
        <table style="border-collapse:separate; border-spacing:10px;">
          <tr>
            <td>通知类型：</td>
            <td>
              <input type="text" id="noticeWay" class="liger-textbox" name="noticeWay" style="width: 170px;background:#ffffff;" value="Email" disabled="disabled" />
            </td>
          </tr>
          <tr>
            <td>通知标题：</td>
            <td>
              <input type="text" id="noticeTitle" class="liger-textbox" name="noticeTitle" style="width: 170px;" />
            </td>
          </tr>
          <tr>
            <td valign="top">通知内容：</td>
            <td>
              <textarea id="noticeContent" name="noticeContent" ></textarea>
            </td>
          </tr>
        </table>
      </div>
    </div>
  </div>
</div>
</body>
</html>
